﻿
@page "/Fin/ReceivableDetail/Create"
@using nERP.ViewModel.Fin.ReceivableDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
  <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit" >
    <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
      <BootstrapInput @bind-Value="@Model.Entity.Seq"/>
      <Select @bind-Value="@Model.Entity.ReceivableId" Items="AllReceivables" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g4427cebc8a4a433d852edbbc2fdd71b7"/>
      <BootstrapInput @bind-Value="@Model.Entity.ReceivableDetailCode"/>
      <Select @bind-Value="@Model.Entity.SaleId" Items="AllSales" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="gf7605b56ff83475d991a0f778c554025"/>
      <BootstrapInput @bind-Value="@Model.Entity.Amount1"/>
      <BootstrapInput @bind-Value="@Model.Entity.Amount2"/>
      <BootstrapInput @bind-Value="@Model.Entity.Amount3"/>
      <BootstrapInput @bind-Value="@Model.Entity.Amount4"/>
      <BootstrapInput @bind-Value="@Model.Entity.Remark"/>
    </Row>

    <div class="modal-footer table-modal-footer">
      <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]"/>
      <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]"/>
    </div>

  </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private ReceivableDetailVM Model = new ReceivableDetailVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {
                        
        
        await PostsForm(vform, "/api/Fin/ReceivableDetail/Create", (s) => "Sys.OprationSuccess");
    }
    public void OnClose()
    {
        CloseDialog();
    }
    
    private List<SelectedItem> AllReceivables = new List<SelectedItem>();
    private List<SelectedItem> AllSales = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {
        
        
        AllReceivables = await WtmBlazor.Api.CallItemsApi("/api/Fin/ReceivableDetail/GetReceivables");
        AllReceivables.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        AllSales = await WtmBlazor.Api.CallItemsApi("/api/Fin/ReceivableDetail/GetSales");
        AllSales.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });

        await base.OnInitializedAsync();
    }
}
